package thread.state;

public class SleepThreadStateTest {
    public static void main(String[] args) {
        Thread mSleepThread = new Thread() {
            @Override
            public void run() {
                System.out.println("Before run() the state is " + this.getState().name());
                super.run();

                try {
                    Thread.sleep(2000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("After run()  the state is " + this.getState().name());
            }
        };

        System.out.println("Before start the state of thread is " + mSleepThread.getState().name());

        mSleepThread.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        /**
         * 当Thread.sleep()时，其处于TIMED_WAITING状态
         * */
        System.out.println("In sleep the state of thread is " + mSleepThread.getState().name());

        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("run finish the state of thread is " + mSleepThread.getState().name());
    }
}
